using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ScottCateAjax2008.UserControls
{
    public partial class SectionLinks : UserControl
    {
        private string sectionTitle;
        public string SectionTitle
        {
            get { return this.sectionTitle; }
            set
            {
                if ( this.sectionTitle != value )
                    this.sectionTitle = value;
            }
        }
        protected void Page_Load ( object sender, EventArgs e )
        {
            MenuPlaceHolder.Controls.Clear();
            foreach (SiteMapNode parent in SiteMap.RootNode.ChildNodes)
            {
                if (parent.Title == SectionTitle)
                {
                    foreach (SiteMapNode child in parent.ChildNodes)
                    {
                        SectionLink sectionLink = (SectionLink)LoadControl("SectionLink.ascx"); 
                        //set hyperlink
                        sectionLink.SectionLinkWrapper.NavigateUrl = child.Url;
                        sectionLink.SectionLinkWrapper.Text = child.Title;
                        sectionLink.SectionLinkWrapper.ToolTip = child.Description;

                        //set description
                        sectionLink.SectionDescription = child.Description;

                        MenuPlaceHolder.Controls.Add(sectionLink);
                    }
                }
            }
        }
    }
}